//
//  XRPageMainSecTableCell.m
//  XClassRoom
//
//  Created by NeiQuan on 16/11/15.
//  Copyright © 2016年 Mr-yuwei. All rights reserved.
//

#import "XRPageMainSecTableCell.h"
#import "XRButtonTopImageButton.h"
@interface XRPageMainSecTableCell ()
{
    
    NSMutableArray *_buttonArray;
    
}
@end
@implementation XRPageMainSecTableCell
-(void)awakeFromNib
{
    [super awakeFromNib];
  
    
}
-(void)addOwnView
{
    _buttonArray=[[NSMutableArray alloc] init];
    NSArray *imagearray=@[@"qq",@"qqkongjian",@"weixin",@"pengyouquan",@"qq",@"qqkongjian",@"pengyouquan",@"weixin"];
    NSArray *titlearray=@[@"每日任务",@"商城",@"直播",@"游戏",@"超市",@"水果",@"美食",@"服饰"];
    CGFloat  buttonwith=(kMainScreenWidth-4*60)/5.0;
    for (NSInteger indexCell=0; indexCell<8; indexCell++)
    {
        XRButtonTopImageButton *button=[[XRButtonTopImageButton alloc] initWithFrame:CGRectMake(buttonwith+indexCell%4*(60+buttonwith), 5*(indexCell/4+1)+indexCell/4*65, 60,65)];
        button.titlelable.text=titlearray[indexCell];
        [button.imageView setImage:[UIImage imageNamed:imagearray[indexCell]]];
        [self.contentView addSubview:button];
        button.tag=1000+indexCell;
        UITapGestureRecognizer  *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickButton:)];
        [button addGestureRecognizer:tap];
        [_buttonArray addObject:button];
    }
}
-(void)clickButton:(UIGestureRecognizer *)ges
{
    
    if (self.delegate&&[self.delegate respondsToSelector:@selector(XRPageMainSecTableCellClickButtonAtindex:inView:)])
    {
        [self.delegate XRPageMainSecTableCellClickButtonAtindex:ges.view .tag-1000 inView:self];
    }
    
}
-(void)setItemArray:(NSArray *)itemArray
{
    _itemArray=itemArray;
    for (NSInteger index=0;index<itemArray.count;index++)
    {
        XRButtonTopImageButton *button=_buttonArray[index];
        button.titlelable.text=_itemArray[index];
       button.imageView.image=[UIImage imageNamed:_imageArray[index]];}
    
}
@end
